import { useCheck } from '@/views/report/directory/useCheck'
import { Column } from '@/components/dynamic-table/types'
import { useSponsor } from '@/views/report/directory/useSponsor'
import { deleteDirectory, recoverOrInvalidDirectory } from '@/api/directory'

export const columns: Column[] = [
  {
    title: '序号',
    dataIndex: 'serial'
  },
  {
    title: '报表编号',
    dataIndex: 'reportNumber'
  },
  {
    title: '报表名称',
    dataIndex: 'reportName'
  },
  {
    title: '监管单位',
    dataIndex: 'regulationDept'
  },
  {
    title: '报表频度',
    dataIndex: 'reportFrequency'
  },
  {
    title: '制度日期',
    dataIndex: 'institutionDate'
  },
  {
    title: '创建人',
    dataIndex: 'creator'
  },
  {
    title: '状态',
    dataIndex: 'status',
    slots: {
      customRender: 'status'
    }
  },
  {
    title: '操作',
    dataIndex: 'action',
    slots: {
      customRender: 'action'
    },
    actions: [
      {
        type: 'text',
        text: '发起',
        style: {
          color: '#34DE28'
        },
        func: ({ record }) => {
          console.log(record.dirId)
          useSponsor('发起', record)
        }
      },
      {
        type: 'text',
        text: '查看',
        style: {
          color: '#FF5500'
        },
        func: ({ record }) => {
          console.log(record)
          useCheck('查看目录', record)
        }
      },
      {
        type: 'text',
        text: '修改',
        style: {
          color: '#0077FF'
        },
        func: ({ record, router }) => {
          console.log(record.reportNumber)
          return new Promise((resolve) => {
            router
              .push({
                path: '/report/directory/modify',
                query: { ...record, title: '修改目录' }
              })
              .then(() => resolve(true))
          })
        }
      },
      {
        type: 'popconfirm',
        text: '删除',
        style: {
          color: '#C6000B'
        },
        func: ({ record }, refreshTableData) => {
          deleteDirectory(record.dirId).then(() => {
            refreshTableData()
          })
        }
      },
      {
        type: 'text',
        text: '恢复',
        style: { color: '#FFBA4F' },
        func: ({ record }, refreshTableData) => {
          recoverOrInvalidDirectory(record.dirId).then(() => {
            refreshTableData()
          })
        }
      }
    ]
  }
]

export const convertFlowNameCode2Chinese = function (code) {
  const codeMap = {
    0: '部门经办',
    1: '部门审核',
    2: '管理信息部经办',
    3: ':管理信息部审核'
  }
  return Reflect.has(codeMap, code) ? codeMap[code] : null
}

export const startMethodChinese2CodeMap = function (name) {
  const methodMap = {
    auto: 0,
    manual: 1
  }
  return Reflect.has(methodMap, name) ? methodMap[name] : null
}
